<?php
class Pageley_Util_BufferedWriter extends Pageley_Util_AbstractWriter {
	
	private $buffer = "";
	private $writer;
	private $bufferSize;
	
	public function __construct($writer, $bufferSize = 4096) {
		$this->writer = $writer;
		$this->bufferSize = $bufferSize;
	}
	
	public function write($text) {
		$this->buffer .= $text;
		if(Pageley_Util_String::length($this->buffer) > $this->bufferSize) {
			$this->flush();
		}
	}
	
	public function flush() {
		$this->writer->write($this->buffer);
		$this->buffer = "";
	}
	
	public function close() {
		$this->flush();
		$this->writer->close();
	}
}